#pragma once
#include <qbytearray.h>

#define u8 uint8_t
#define u16 uint16_t

#define HUP_FRAME_PREFIX_NUMBER 5
#define HUP_FRAME_HOST_HDR_H 0xAA
#define HUP_FRAME_HOST_HDR_L 0xDD
#define HUP_FRAME_CLIENT_HDR_H 0xBB
#define HUP_FRAME_CLIENT_HDR_L 0xDD

typedef enum _hup_protocol_state_e {
    EM_HUP_STATE_HDR_H,
    EM_HUP_STATE_HDR_L,
    EM_HUP_STATE_CMD,
    EM_HUP_STATE_DATA_LEN_L,
    EM_HUP_STATE_DATA_LEN_H,
    EM_HUP_STATE_DATA,
    EM_HUP_STATE_CRC
}hup_protocol_state_e;

typedef enum _hup_role_e {
    EM_HUP_ROLE_MASTER = 0x11,
    EM_HUP_ROLE_SLAVE
}hup_role_e;

typedef enum _hup_timer_state_e {
    EM_HUP_TIMER_ENABLE = 0x21,
    EM_HUP_TIMER_DISABLE
}hup_timer_state_e;

typedef struct _hup_protocol_type {

    u8 hdr_h;

    u8 hdr_l;

    u8 cmd;

    u8 data_len_l;

    u8 data_len_h;

    u8* data_addr;

    u8 xor8;

}hup_protocol_type_t;

typedef struct _hup_handle_type {

    hup_role_e role;

    hup_timer_state_e timer_state;

    u16 frame_data_len;
}hup_handle_type_t;

class HupProtocal
{
public:
	static QByteArray encode(hup_role_e role, u8 cmd, QByteArray data);
	//static QByteArray decode();

private:
    static u8 cal_xor8(QByteArray data);
};